package aqua.smile.wx.handler;

import me.chanjar.weixin.common.session.WxSessionManager;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.message.WxMpXmlMessage;
import me.chanjar.weixin.mp.bean.message.WxMpXmlOutMessage;
import org.springframework.stereotype.Component;

import java.util.Map;

import static me.chanjar.weixin.common.api.WxConsts.EventType;

/**
 * @author Binary Wang(https://github.com/binarywang)
 */
@Component
public class MenuMpHandler extends AbstractMpHandler {

    @Override
    public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage,
                                    Map<String, Object> context, WxMpService weixinService,
                                    WxSessionManager sessionManager) {
        String msg = String.format("type:%s, event:%s, key:%s",
            wxMessage.getMsgType(), wxMessage.getEvent(),
            wxMessage.getEventKey());
        if (EventType.VIEW.equals(wxMessage.getEvent())) {
            return null;
        }
        
//        //wxMessage.getEventKey();
        String url = "http://ul40692621.qicp.vip:17211/mgsapp/?openId=o1W8x6AaOMCirR4Fx_YU0MhtCgmE";
//        List<WxMpXmlOutNewsMessage.Item> articles = new ArrayList<>();
//        WxMpXmlOutNewsMessage.Item item = new WxMpXmlOutNewsMessage.Item();
//        item.setTitle("Title");
//        item.setDescription("description");
//        item.setUrl(url);
//        articles.add(item);
//        
//        return WxMpXmlOutMessage.NEWS().articles(articles).fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser()).build();

        return WxMpXmlOutMessage.TEXT().content(url)
            .fromUser(wxMessage.getToUser()).toUser(wxMessage.getFromUser())
            .build();
    }

}
